package cn.yitun.chat.yitunserverimapicore.business.video.action;

import cn.yitun.chat.yituncommonmessage.ExceptionEnum;
import cn.yitun.chat.yituncommonmessage.YitunException;
import cn.yitun.chat.yituncommonmessage.impl.HeadImpl;
import cn.yitun.chat.yituncommonmessage.result.ResultMessage;
import cn.yitun.chat.yituncommonutil.YitunStringUtil;
import cn.yitun.chat.yitungeneral.annotation.action.ActionMapping;
import cn.yitun.chat.yitungeneral.annotation.parameter.JsonDefine;
import cn.yitun.chat.yitunservercommonlib.constant.ActionTypeConstant;
import cn.yitun.chat.yitunservercommonlib.dataentity.dto.remote.VideoPushDto;
import cn.yitun.chat.yitunservercommonlib.util.NumUtil;
import cn.yitun.chat.yitunserverimcore.general.main.push.video.VideoPush;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 
 * @author yitun
 *
 */
@Component
@ActionMapping(value = ActionTypeConstant.VIDEO_ACTION_PUSH)
public class VideoAction {

	@Resource
	VideoPush videoPush;

	/**
	 * 获取视频服务地址
	 * 
	 * @return
	 */
	@ActionMapping(value = "1.1.0001")
	public ResultMessage getVideoServerPort() {
		ResultMessage message = new ResultMessage();
		message.bodyPut("videoAddress", null);
		return message;
	}

	/**
	 * 获取用户的视频地�?
	 * 
	 * @return
	 */
	@ActionMapping(value = "1.1.0003")
	public ResultMessage getUserVideoAddress() {
		ResultMessage message = new ResultMessage();
		message.bodyPut("videoAddress", null);
		return message;
	}

	/**
	 * 向用户发生视频请�?
	 * 
	 * @param head
	 * @param videoPushDto
	 */
	@ActionMapping(value = "1.1.0004")
	public void videoRequest(HeadImpl head, @JsonDefine("data") VideoPushDto videoPushDto) {
		if (NumUtil.isInValid(videoPushDto.getReceiveUserId()) || NumUtil.isInValid(videoPushDto.getSendUserId()))
			throw new YitunException(ExceptionEnum.LOSE_FILED);
		videoPush.pushRequestVideo(head.getKey(), videoPushDto.getReceiveUserId(), videoPushDto.getSendUserId());
	}

	/**
	 * 响应用户的视频请�?
	 * 
	 * @param head
	 * @param videoPushDto
	 */
	@ActionMapping(value = "1.1.0005")
	public void videoResponse(HeadImpl head, @JsonDefine("data") VideoPushDto videoPushDto) {

		if (NumUtil.isInValid(videoPushDto.getReceiveUserId()) || NumUtil.isInValid(videoPushDto.getSendUserId())
				|| YitunStringUtil.isEmpty(videoPushDto.getActionType()))
			throw new YitunException(ExceptionEnum.LOSE_FILED);

		videoPush.pushResponseVideo(head.getKey(),
				videoPushDto.getSendUserId(),
				videoPushDto.getReceiveUserId(),
				videoPushDto.getActionType());
	}
}
